package com.xhs.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xhs.dao.UserDatilDao;
import com.xhs.dto.DatilUpdataDto;
import com.xhs.entity.UserDatil;
import com.xhs.service.intf.UserDatilService;
import com.xhs.utils.BeanUtil;
import com.xhs.utils.RUtil;
import com.xhs.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserDatilServiceImpl implements UserDatilService {

    @Autowired
    private UserDatilDao dao;


    @Override
    public R updataUserDatil(DatilUpdataDto datil) {
        UserDatil userDatil = BeanUtil.copyProperty(UserDatil.class, datil, datil.getClass().getFields());
        userDatil.setUid(datil.getUid());
        return dao.updateById(userDatil)>0? RUtil.ok(null):RUtil.fail();
    }

    @Override
    public R queryById(int uid) {
        UserDatil userDatil = dao.selectOne(new QueryWrapper<UserDatil>().eq("uid", uid));
        return RUtil.ok(userDatil);
    }

    @Override
    public R updataHeadUrl(int uid, String url) {

        return dao.updataHeadUrl(url, uid)>0? RUtil.ok(null):RUtil.fail();
    }
}
